
package com.rt.schedulenew.utils.checkparam.common;
import org.springframework.util.CollectionUtils;
import java.util.Collection;
import org.springframework.util.StringUtils;
import java.util.function.BiFunction;
public enum Operator
{
    GREATER_THAN(">", Operator::isGreaterThan), 
    GREATER_THAN_EQUAL(">=", Operator::isGreaterThanEqual), 
    LESS_THAN("<", Operator::isLessThan), 
    LESS_THAN_EQUAL("<=", Operator::isLessThanEqual), 
    NOT_EQUAL("!=", Operator::isNotEqual), 
    NOT_NULL("not null", Operator::isNotNull);
    
    public String value;
    private BiFunction<Object, String, Boolean> fun;
    
    private Operator(final String value, final BiFunction<Object, String, Boolean> fun) {
        this.value = value;
        this.fun = fun;
    }
    
    private static Boolean isNotNull(final Object value, final String operatorNum) {
        Boolean isNotNull = Boolean.TRUE;
        final Boolean isStringNull = value instanceof String && StringUtils.isEmpty((Object)value);
        final Boolean isCollectionNull = value instanceof Collection && CollectionUtils.isEmpty((Collection)value);
        if (value == null) {
            isNotNull = Boolean.FALSE;
        }
        else if (isStringNull || isCollectionNull) {
            isNotNull = Boolean.FALSE;
        }
        return isNotNull;
    }
    
    private static Boolean isGreaterThan(final Object value, final String operatorNum) {
        Boolean isGreaterThan = Boolean.FALSE;
        if (value == null) {
            return Boolean.FALSE;
        }
        final Boolean isStringGreaterThen = value instanceof String && ((String)value).length() > Integer.valueOf(operatorNum);
        final Boolean isLongGreaterThen = value instanceof Long && (long)value > Long.valueOf(operatorNum);
        final Boolean isIntegerGreaterThen = value instanceof Integer && (int)value > Integer.valueOf(operatorNum);
        final Boolean isShortGreaterThen = value instanceof Short && (short)value > Short.valueOf(operatorNum);
        final Boolean isFloatGreaterThen = value instanceof Float && (float)value > Float.valueOf(operatorNum);
        final Boolean isDoubleGreaterThen = value instanceof Double && (double)value > Double.valueOf(operatorNum);
        final Boolean isCollectionGreaterThen = value instanceof Collection && ((Collection)value).size() > Integer.valueOf(operatorNum);
        if (isStringGreaterThen || isLongGreaterThen || isIntegerGreaterThen || isShortGreaterThen || isFloatGreaterThen || isDoubleGreaterThen || isCollectionGreaterThen) {
            isGreaterThan = Boolean.TRUE;
        }
        return isGreaterThan;
    }
    
    private static Boolean isGreaterThanEqual(final Object value, final String operatorNum) {
        Boolean isGreaterThanEqual = Boolean.FALSE;
        if (value == null) {
            return Boolean.FALSE;
        }
        final Boolean isStringGreaterThenEqual = value instanceof String && ((String)value).length() >= Integer.valueOf(operatorNum);
        final Boolean isLongGreaterThenEqual = value instanceof Long && (long)value >= Long.valueOf(operatorNum);
        final Boolean isIntegerGreaterThenEqual = value instanceof Integer && (int)value >= Integer.valueOf(operatorNum);
        final Boolean isShortGreaterThenEqual = value instanceof Short && (short)value >= Short.valueOf(operatorNum);
        final Boolean isFloatGreaterThenEqual = value instanceof Float && (float)value >= Float.valueOf(operatorNum);
        final Boolean isDoubleGreaterThenEqual = value instanceof Double && (double)value >= Double.valueOf(operatorNum);
        final Boolean isCollectionGreaterThenEqual = value instanceof Collection && ((Collection)value).size() >= Integer.valueOf(operatorNum);
        if (isStringGreaterThenEqual || isLongGreaterThenEqual || isIntegerGreaterThenEqual || isShortGreaterThenEqual || isFloatGreaterThenEqual || isDoubleGreaterThenEqual || isCollectionGreaterThenEqual) {
            isGreaterThanEqual = Boolean.TRUE;
        }
        return isGreaterThanEqual;
    }
    
    private static Boolean isLessThan(final Object value, final String operatorNum) {
        Boolean isLessThan = Boolean.FALSE;
        if (value == null) {
            return Boolean.FALSE;
        }
        final Boolean isStringLessThen = value instanceof String && ((String)value).length() < Integer.valueOf(operatorNum);
        final Boolean isLongLessThen = value instanceof Long && (long)value < Long.valueOf(operatorNum);
        final Boolean isIntegerLessThen = value instanceof Integer && (int)value < Integer.valueOf(operatorNum);
        final Boolean isShortLessThen = value instanceof Short && (short)value < Short.valueOf(operatorNum);
        final Boolean isFloatLessThen = value instanceof Float && (float)value < Float.valueOf(operatorNum);
        final Boolean isDoubleLessThen = value instanceof Double && (double)value < Double.valueOf(operatorNum);
        final Boolean isCollectionLessThen = value instanceof Collection && ((Collection)value).size() < Integer.valueOf(operatorNum);
        if (isStringLessThen || isLongLessThen || isIntegerLessThen || isShortLessThen || isFloatLessThen || isDoubleLessThen || isCollectionLessThen) {
            isLessThan = Boolean.TRUE;
        }
        return isLessThan;
    }
    
    private static Boolean isLessThanEqual(final Object value, final String operatorNum) {
        Boolean isLessThanEqual = Boolean.FALSE;
        if (value == null) {
            return Boolean.FALSE;
        }
        final Boolean isStringLessThenEqual = value instanceof String && ((String)value).length() <= Integer.valueOf(operatorNum);
        final Boolean isLongLessThenEqual = value instanceof Long && (long)value <= Long.valueOf(operatorNum);
        final Boolean isIntegerLessThenEqual = value instanceof Integer && (int)value <= Integer.valueOf(operatorNum);
        final Boolean isShortLessThenEqual = value instanceof Short && (short)value <= Short.valueOf(operatorNum);
        final Boolean isFloatLessThenEqual = value instanceof Float && (float)value <= Float.valueOf(operatorNum);
        final Boolean isDoubleLessThenEqual = value instanceof Double && (double)value <= Double.valueOf(operatorNum);
        final Boolean isCollectionLessThenEqual = value instanceof Collection && ((Collection)value).size() <= Integer.valueOf(operatorNum);
        if (isStringLessThenEqual || isLongLessThenEqual || isIntegerLessThenEqual || isShortLessThenEqual || isFloatLessThenEqual || isDoubleLessThenEqual || isCollectionLessThenEqual) {
            isLessThanEqual = Boolean.TRUE;
        }
        return isLessThanEqual;
    }
    
    private static Boolean isNotEqual(final Object value, final String operatorNum) {
        Boolean isNotEqual = Boolean.FALSE;
        if (value == null) {
            return Boolean.FALSE;
        }
        final Boolean isStringNotEqual = value instanceof String && !value.equals(operatorNum);
        final Boolean isLongNotEqual = value instanceof Long && !value.equals(Long.valueOf(operatorNum));
        final Boolean isIntegerNotEqual = value instanceof Integer && !value.equals(Integer.valueOf(operatorNum));
        final Boolean isShortNotEqual = value instanceof Short && !value.equals(Short.valueOf(operatorNum));
        final Boolean isFloatNotEqual = value instanceof Float && !value.equals(Float.valueOf(operatorNum));
        final Boolean isDoubleNotEqual = value instanceof Double && !value.equals(Double.valueOf(operatorNum));
        final Boolean isCollectionNotEqual = value instanceof Collection && ((Collection)value).size() != Integer.valueOf(operatorNum);
        if (isStringNotEqual || isLongNotEqual || isIntegerNotEqual || isShortNotEqual || isFloatNotEqual || isDoubleNotEqual || isCollectionNotEqual) {
            isNotEqual = Boolean.TRUE;
        }
        return isNotEqual;
    }
}
